import axios from 'axios';
import apiConfig from './api.config';

function send (path, dataContent, isGet = true) {
    return new Promise((resolve, reject) => {
        let listStr = dataContent;
        listStr = listStr.replace(/null/g, '').replace(/undefined/g, '');

        listStr = listStr.replace(/\t/g, ' ').replace(/🈹/g, '\\t');
        dataContent = listStr;
        //处理图片路径
        let params = { dataContent };
        // 如果path有前置/,就去掉
        path = path.replace(/^\//, '');
        axios({
            url: `./${path}`,
            method: isGet ? 'get' : 'post',
            params: isGet ? params : {},
            data: isGet ? {} : params,
            dataType: "text",
            baseURL: apiConfig.baseUrl193,
        }).then((response) => {
            resolve(response.data);
        }).catch(err => {
            console.log('err :>> ', err);
            reject(err);
        });
    });
}

const myAxios193 = {
    get (path, dataContent) {
        dataContent = dataContent ? dataContent : '{}';
        return send(path, dataContent, true);
    },
    post (path, dataContent) {
        dataContent = dataContent ? dataContent : '{}';
        return send(path, dataContent, false);
    },
};
export default myAxios193;
